#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>

#define HELLO_DBG
#ifdef HELLO_DBG
#define hello_dbg(fmt, ...) printf("[%s][%d]" fmt "\r\n", __func__, __LINE__, ##__VA_ARGS__)
#else
#define hello_dbg(fmt, ...)
#endif

#define DEV_NMAE "/dev/ttyVir"

int main(void)
{
    int fd;
    int len;
    char send[128] = "test hello char";
    char recv[128] = {0};
    char dev_name[128] = "";

    hello_dbg("");

    snprintf(dev_name, sizeof(dev_name), "%s%d", DEV_NMAE, 0);

    fd = open(dev_name, O_RDWR);
    if (fd < 0)
    {
        hello_dbg("open %s error, erron:%d:%s", dev_name, errno, strerror(errno));
        return -1;
    }

    len = write(fd, send, strlen(send));
    hello_dbg("write return len:%d", len);

    memset(recv, 0, sizeof(recv));
    len = read(fd, recv, sizeof(recv));
    hello_dbg("read %d return len:%d, %s", sizeof(recv), len, recv);

    memset(recv, 0, sizeof(recv));
    len = read(fd, recv, 10);
    hello_dbg("read 10 return len:%d, %s", len, recv);

    close(fd);

    return 0;
}
